package cn.stylefeng.guns.sys.modular.system.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.sys.modular.system.entity.BtyCwPankui;
import cn.stylefeng.guns.sys.modular.system.mapper.BtyCwPankuiMapper;
import cn.stylefeng.guns.sys.modular.system.model.params.BtyCwPankuiParam;
import cn.stylefeng.guns.sys.modular.system.model.result.BtyCwPankuiResult;
import cn.stylefeng.guns.sys.modular.system.service.BtyCwPankuiService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 盘亏表 服务实现类
 * </p>
 *
 * @author 
 * @since 2021-11-02
 */
@Service
public class BtyCwPankuiServiceImpl extends ServiceImpl<BtyCwPankuiMapper, BtyCwPankui> implements BtyCwPankuiService {

    @Override
    public void add(BtyCwPankuiParam param){
        BtyCwPankui entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(BtyCwPankuiParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(BtyCwPankuiParam param){
        BtyCwPankui oldEntity = getOldEntity(param);
        BtyCwPankui newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public BtyCwPankuiResult findBySpec(BtyCwPankuiParam param){
        return null;
    }

    @Override
    public List<BtyCwPankuiResult> findListBySpec(BtyCwPankuiParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(BtyCwPankuiParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(BtyCwPankuiParam param){
        return param.getPankuiId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private BtyCwPankui getOldEntity(BtyCwPankuiParam param) {
        return this.getById(getKey(param));
    }

    private BtyCwPankui getEntity(BtyCwPankuiParam param) {
        BtyCwPankui entity = new BtyCwPankui();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
